package com.fs.system.sys_admin.controller;

import com.fs.system.college_admin.domain.College;
import com.fs.system.common.ResponseData;
import com.fs.system.sys_admin.service.SysCollegeService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sysAdminCollege")
public class SysCollegeController {

    @Resource
    private SysCollegeService sysCollegeService;

    /**
     * 查询所有学院
     * @param college
     * @return
     */
    @GetMapping("/selectAll")
    public ResponseData selectAllCollegeList(College college)
    {
        List<College> dbCollegeList = sysCollegeService.selectAllCollegeList(college);
        return new ResponseData("200","查询成功",dbCollegeList);
    }

    /**
     * 分页查询所有学院
     * @param college
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPage")
    public ResponseData selectPage(College college,
                                   @RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "5") Integer pageSize)
    {
        PageInfo<College> dbCollegeList = sysCollegeService.selectPage(college,pageNum,pageSize);
        return new ResponseData("200","查询成功",dbCollegeList);
    }

    /**
     * 添加学院
     * @param college
     * @return
     */
    @PostMapping("/addCollege")
    public ResponseData addCollege(@RequestBody College college)
    {
        sysCollegeService.addCollege(college);
        return new ResponseData("200","添加成功",null);
    }

    /**
     * 修改学院
     * @param college
     * @return
     */
    @PutMapping("/updateCollege")
    public ResponseData updateCollege(@RequestBody College college){
        sysCollegeService.updateCollege(college);
        return new ResponseData("200","修改成功",null);
    }

    /**
     * 删除学院
     * @param collegeId
     * @param updatedBy
     * @return
     */
    @PutMapping("/deleteCollege/{collegeId}")
    public ResponseData deleteCollege(@PathVariable Long collegeId,@RequestParam String updatedBy){
        sysCollegeService.deleteCollege(collegeId,updatedBy);
        return new ResponseData("200","删除成功",null);
    }

    /**
     * 批量删除学院
     * @param ids
     * @param updatedBy
     * @return
     */
    @PutMapping("/deleteCollegeBatch/{updatedBy}")
    public ResponseData deleteBatch(@PathVariable String updatedBy,@RequestBody List<Long> ids){
        sysCollegeService.deleteBatch(ids,updatedBy);
        return new ResponseData("200","批量删除成功",null);
    }
}
